package dao

import (
	"fmt"
	Mysql "selfService/Databases"
	"selfService/兴趣相关/models"
)

type UserInterMidDao struct {

}

// ←
// 传入人物id 返回匹配该人物id的数据
func (this *UserInterMidDao)GetInterestById(user_id string)*[]models.User_inter_mid  {
	result := &[]models.User_inter_mid{}
	Mysql.DB.Where("user_id = ?", user_id).Find(result)
	return result
}

// ←
// 根据id 修改个人兴趣
func (*UserInterMidDao)ChangeInterest(midId string,IntereId string)string  {
 	// db.Model(&user).Where("active = ?", true).Update("name", "hello")
	User_inter_mid := &models.User_inter_mid{}
	Mysql.DB.Model(&User_inter_mid).Where("id = ?",midId).Update("inter_id",IntereId)
	fmt.Println("修改成功,修改后的值为")
	fmt.Println(User_inter_mid.Inter_id == IntereId)
	if User_inter_mid.Inter_id == IntereId {
		return "成功"
	}else {
		return "失败"
	}
}

// ←
// 根据id 删除个人关联兴趣
func (*UserInterMidDao)DeleteSelfInterest(id string)bool  {
//db.Where("email LIKE ?", "%jinzhu%").Delete(Email{})
	////// DELETE from emails where email LIKE "%jinhu%";
	result := &models.User_inter_mid{}
	Mysql.DB.Where("id = ?",id).Delete(result)
	return true
}

func (this *UserInterMidDao) Insert(mod *models.User_inter_mid) string {
	create := Mysql.DB.Create(mod)
	if create.Error == nil{
		return "成功"
	}else {
		return create.Error.Error()
	}
}

//

